//
//  ShopBottomView.m
//  JewelryStore
//
//  Created by apple on 2016/12/22.
//  Copyright © 2016年 com. All rights reserved.
//

#import "ShopBottomView.h"

@interface ShopBottomView ()
@property (nonatomic, strong) UIImageView *backView;
@property (nonatomic, strong) UILabel *allMoneyValue;
@property (nonatomic, strong) UIButton *gotoPay;
@end

@implementation ShopBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self cofigureUI:frame];
        
    }
    return self;
}

- (void)cofigureUI:(CGRect)frame
{
    CGRect backFrame = CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame));
    UIImageView *backView = [[UIImageView alloc] initWithFrame:backFrame];
    backView.image = KImageNamed(@"bottomBV");
    backView.userInteractionEnabled = YES;
    [self addSubview:backView];

    //勾选
    UIButton *selectAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [selectAllBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    selectAllBtn.userInteractionEnabled = YES;
    selectAllBtn.titleLabel.font = Font(16);
    [selectAllBtn setImage:KImageNamed(@"m_noselect") forState:UIControlStateNormal];
    [selectAllBtn setTitle:@"  全选" forState:UIControlStateNormal];
    [selectAllBtn addTarget:self action:@selector(selectAllClick:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:selectAllBtn];
    [selectAllBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@5);
        make.top.equalTo(@0);
        make.width.equalTo(@80);
        make.height.equalTo(@(SCREEN_WIDTH/5.5));
    }];
    
    //合计
    UILabel *allMoney = [[UILabel alloc] init];
    allMoney.text = @"合计:";
    allMoney.font = Font(19);
    [backView addSubview:allMoney];
    [allMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(selectAllBtn.mas_right).offset(0);
        make.top.equalTo(@0);
        make.width.equalTo(@55);
        make.height.equalTo(@(SCREEN_WIDTH/5.5));
        
    }];
    
    _allMoneyValue = [[UILabel alloc] init];
    _allMoneyValue.text = [NSString stringWithFormat:@"￥%@", @"0.00"];
    _allMoneyValue.font = Font(19);
    [backView addSubview:_allMoneyValue];
    [_allMoneyValue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(allMoney.mas_right).offset(0);
        make.top.equalTo(@0);
        make.height.equalTo(allMoney.mas_height);
        make.width.equalTo(@(SCREEN_WIDTH/3.7));
    }];
    
    //去结算
    _gotoPay = [UIButton buttonWithType:UIButtonTypeCustom];
    _gotoPay.titleLabel.font = Font(19);
    [_gotoPay setTitle:@"去结算(0)" forState:UIControlStateNormal];
    [_gotoPay setBackgroundImage:KImageNamed(@"gotoPay_background") forState:UIControlStateNormal];
    [backView addSubview:_gotoPay];
    [_gotoPay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_allMoneyValue.mas_right).offset(0);
        make.top.and.right.and.bottom.equalTo(@0);
    }];

    __block UIButton *blockBtn = selectAllBtn;
    
    __block UILabel *money = _allMoneyValue;
    
    __block UIButton *num = _gotoPay;
    
    self.block = ^(CHANGESTATUSTYPE status, CGFloat allPrice, int allNum){
        
        switch (status) {
            case CHANGEALLSTATUS:
            {
                [blockBtn setImage:KImageNamed(@"s_select") forState:UIControlStateNormal];
            }
                break;
            case CHANGENOOFALLSTATUS:
            {
                [blockBtn setImage:KImageNamed(@"m_noselect") forState:UIControlStateNormal];
            }
                break;
            case CHANGEKEEPSTATUS:
            {
                TT_Log(@"keepStaus");
            }
                break;
            default:
                break;
        }
        
        money.text = [NSString stringWithFormat:@"%.2f", allPrice];

        [num setTitle:[NSString stringWithFormat:@"去结算(%d)", allNum] forState:UIControlStateNormal];

    };

}

#pragma mark - private

- (void)selectAllClick:(UIButton *)button
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectAllCell)]) {
        
        [self.delegate selectAllCell];

    }
}
@end
